package com.star.controller.admin;

import com.star.dto.OrdersPageQueryDTO;
import com.star.result.PageResult;
import com.star.result.Result;
import com.star.service.OrderService;
import com.star.vo.OrderStatisticsVO;
import com.star.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Api(tags ="管理员端订单管理相关接口")
public class OrdersController {
    @Autowired
    private OrderService orderService;

    /**
     * 订单搜索
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("/conditionSearch")
    @ApiOperation("订单搜索")
    public Result<PageResult> page(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("订单搜索:{}", ordersPageQueryDTO);
        PageResult pageResult = orderService.pageQuery(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 各个状态的订单数量统计
     * @return
     */
    @GetMapping("/statistics")
    @ApiOperation("各个状态的订单数量统计")
    public Result<OrderStatisticsVO> getOrderStatistics(Long businessId) {
        log.info("各个状态的订单数量统计");
        return Result.success(orderService.getOrderStatistics(businessId));
    }

    /**
     * 获取订单详情
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    @ApiOperation("订单详情")
    public Result<OrderVO> detail(@PathVariable Long id){
        log.info("订单详情{}", id);
        OrderVO orderVO = orderService.adminOrderDetail(id);
        return Result.success(orderVO);
    }

}
